# -*- coding: utf-8 -*-
import os
import sys
import xbmc
import urllib

##General vars
__plugin__ = "xbVOD-IL"
__author__ = "thevoddb.org"
__url__ = "http://thevoddb.org"
__svn_url__ = "http://xbvod.sourceforge.net/svn/trunk/plugins/video/thevoddb/"
__credits__ = ""
__version__ = "0.0.421"
__XBMC_Revision__ = ""

LIB_PATH = xbmc.translatePath( os.path.join( os.getcwd(), 'resources', 'lib' ) )
sys.path.append (LIB_PATH)

from xbPlugin import *

def get_params():
    param=[]
    paramstring=sys.argv[2]
    if len(paramstring)>=2:
        params=sys.argv[2]
        cleanedparams=params.replace('?','')
        if (params[len(params)-1]=='/'):
            params=params[0:len(params)-2]
        pairsofparams=cleanedparams.split('&')
        param={}
        for i in range(len(pairsofparams)):
            splitparams={}
            splitparams=pairsofparams[i].split('=')
            if (len(splitparams))==2:
                param[splitparams[0]]=splitparams[1]
                            
    return param

if ( __name__ == "__main__" ):
    plugin = xbPlugin()    
    if ( not sys.argv[ 2 ] ):
        plugin.ChannelList()
        
    elif ( sys.argv[ 2 ] ):
        params = get_params()
        try:
            ChannelName = urllib.unquote_plus(params["ChannelName"])
            ChannelID = urllib.unquote_plus(params["ChannelID"])
            plugin.Channel(ChannelName, ChannelID)
        except:
            pass
        
        try:
            Channel = urllib.unquote_plus(params["Channel"])
            SeriesID = urllib.unquote_plus(params["SeriesID"])
            SeriesName = urllib.unquote_plus(params["SeriesName"])
            Season = urllib.unquote_plus(params["Season"])
            plugin.Series(Channel, SeriesName, SeriesID, Season)
        except:
            pass
            
##We're done
sys.modules.clear()
